home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / CATALOG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-06  |  1.2 KB  |  62 lines

  1. #include "global.h"
  2.  
  3. #if !defined(_lint)
  4. static char rcsid[] OPTIONAL = "$Id: catalog.c,v 1.14 1997/09/07 00:31:16 root Exp root $";
  5. #endif
  6.  
  7. #ifdef CATALOG
  8. #include "files.h"
  9.  
  10. char * catalog (int base, int theindex);
  11. int catalog_check (void);
  12. extern unsigned long filelength (int);
  13.  
  14. static FILE *strfp = NULLFILE;
  15.  
  16. char *
  17. catalog (base, theindex)
  18. int base, theindex;
  19. {
  20. static char stringbuf[256];
  21. long seekto;
  22.  
  23.     stringbuf[0] = 0;
  24.     do    {
  25.         if (!strfp)    {
  26.             if ((strfp = fopen (CATALOGfile, READ_BINARY)) == NULLFILE)    {
  27.                 (void) fprintf (stderr, "\n\r\n\007Can't open catalog file '%s'!\n", CATALOGfile);
  28.                 (void) fflush (stderr);
  29.                 kpause (10000);
  30.                 where_outta_here (0, "catalog");
  31.             }
  32.         }
  33.  
  34.         seekto = base + theindex;
  35.         seekto *= 256;
  36.         if (fseek (strfp, seekto, SEEK_SET))
  37.             /* file seems to have been closed behind out backs! */
  38.             strfp = NULLFILE;
  39.     } while (!strfp);
  40.  
  41.     (void) fread (stringbuf, 1, 256, strfp);
  42.     return (stringbuf);
  43. }
  44.  
  45. int
  46. catalog_check (void)
  47. {
  48. char *vers, *cp;
  49.  
  50.     vers = catalog (0, 0);
  51.     cp = strstr (&vers[1], "TNOS");
  52.     if (!cp || (filelength(fileno(strfp)) % 256L) != 0L)
  53.         return -1;
  54.     cp += 5;
  55.     if (strncmp (VERSION, cp, strlen(VERSION)))
  56.         return 1;
  57.     else
  58.         return 0;
  59. }
  60.  
  61. #endif
  62.